package com.itheima.array;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        int[] arr = {42, 78, 85, 21, 74};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要查找的元素:");
        int num = sc.nextInt();
        int index = -1;
        for (int i = 0; i < arr.length; i++)
            if (arr[i] == num) {
                index = arr[i];
                System.out.println("index=" + index);
                for (int ei = 0; ei < arr.length; ei++) {
                    if (arr[ei] == num) {
                        index = ei;
                        System.out.println("index+" + index);
                    }
                }
                if (index == -1) {
                    System.out.println("index=" + index);
                }
            }
    }
}
